package com.edu.neusoft.elec_shop.controller;

import com.edu.neusoft.elec_shop.domain.Comments;
import com.edu.neusoft.elec_shop.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    // 根据评论编号删除评论
    @DeleteMapping("/{commenttId}")
    public int deleteByPrimaryKey(@PathVariable("commenttId") Long commenttId) {
        return commentsService.deleteByPrimaryKey(commenttId);
    }

    // 插入一条评论
    @PostMapping
    public int insert(@RequestBody Comments record) {
        return commentsService.insert(record);
    }

    // 有选择地插入一条评论（只插入非空字段）
    @PostMapping("/selective")
    public int insertSelective(@RequestBody Comments record) {
        return commentsService.insertSelective(record);
    }

    // 根据评论编号查询评论
    @GetMapping("/{commenttId}")
    public Comments selectByPrimaryKey(@PathVariable("commenttId") Long commenttId) {
        return commentsService.selectByPrimaryKey(commenttId);
    }

    // 根据评论编号有选择地更新评论（只更新非空字段）
    @PutMapping("/selective")
    public int updateByPrimaryKeySelective(@RequestBody Comments record) {
        return commentsService.updateByPrimaryKeySelective(record);
    }

    // 根据评论编号更新评论
    @PutMapping
    public int updateByPrimaryKey(@RequestBody Comments record) {
        return commentsService.updateByPrimaryKey(record);
    }
}